package com.example.wzdjcrdpassword.repository;

import com.example.wzdjcrdpassword.entity.UserReport;
import org.springframework.data.jpa.repository.JpaRepository;
import org.springframework.data.jpa.repository.Query;
import org.springframework.data.repository.query.Param;
import org.springframework.stereotype.Repository;

import java.util.List;

@Repository
public interface UserReportRepository extends JpaRepository<UserReport, Long> {
    
    /**
     * 根据业务ID查询
     */
    UserReport findByBusinessId(String businessId);
    
    /**
     * 根据MAC地址查询
     */
    List<UserReport> findByMacAddress(String macAddress);
    
    /**
     * 根据MAC地址和删除状态查询
     */
    List<UserReport> findByMacAddressAndIsDeleted(String macAddress, String isDeleted);
    
    /**
     * 查询所有有效的数据上报记录
     */
    @Query("SELECT u FROM UserReport u WHERE u.isDeleted = 'NO'")
    List<UserReport> findAllActiveReports();
    
    /**
     * 根据MAC地址和时间范围查询
     */
    @Query("SELECT u FROM UserReport u WHERE u.macAddress = :macAddress AND u.createTime BETWEEN :startTime AND :endTime AND u.isDeleted = 'NO'")
    List<UserReport> findByMacAddressAndTimeRange(@Param("macAddress") String macAddress, 
                                                 @Param("startTime") java.time.LocalDateTime startTime, 
                                                 @Param("endTime") java.time.LocalDateTime endTime);
}